package com.bosicen.crm.web.controller;



import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bosicen.crm.dao.entity.Dealer;
import com.bosicen.crm.dao.entity.ProductTable;
import com.bosicen.crm.dao.entity.ProductType;
import com.bosicen.crm.dao.entity.User;
import com.bosicen.crm.service.CommonServiceImpl;
import com.bosicen.crm.service.orders.OrdersServiceImpl;
import com.bosicen.crm.service.sysmanage.DealerServiceImpl;
import com.bosicen.crm.service.sysmanage.ProductTypeServiceImpl;
import com.bosicen.crm.tools.AppUtil;

/****
 * 页面跳转类
 * @author niyong
 *
 */

@Controller
@RequestMapping("/redirect")
public class RedirectController {
	@Autowired
	OrdersServiceImpl ordersservice;
	@Autowired
	DealerServiceImpl dealerService;
	@Autowired
	ProductTypeServiceImpl productTypeService;
	@Autowired
	CommonServiceImpl commonService;
	/***
	 * main  页面
	 * @return
	 */
	@RequestMapping(value="/main")
	public String main(){
		return "admin";
	}

	/***
	 * top  页面
	 * @return
	 */
	@RequestMapping(value="/top")
	public String top(){
		return "top";
	}
	
	/***
	 * left  页面
	 * @return
	 */
	@RequestMapping(value="/left")
	public String left(){
		return "left";
	}
	
	/***
	 * bot   页面
	 * @return
	 */
	@RequestMapping(value="/bot")
	public String bot(){
		return "bot";
	}
	
	
	
	/***
	 * error  页面
	 * @return
	 */
	@RequestMapping(value="/error")
	public String error(){
		return "error";
	}
	
	/***
	 * 订单搜索
	 * @return
	 */
	@RequestMapping(value="/redirect_search_orders")
	public String search_orders(){
		return "orders/search_orders";
	}
	/***
	 * 下订单
	 * @return
	 */
	@RequestMapping(value="/addorder")
	public String addorder(HttpServletRequest request){
		request.setAttribute("orderno", AppUtil.findorderno(this.ordersservice.findOrders4day()));
		User user=(User) request.getSession().getAttribute("userinfo");
		List<Dealer> list=this.dealerService.findDealerList(user.getCompanyid());
		request.setAttribute("dealer_list", list);
		return "orders/addorder";
	}
	/****
	 * 跳转到新增订单详细页面
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/addorderdetails/{orderid}/{type}")
	public String AddOrderDetails(HttpServletRequest request,@PathVariable("orderid") Integer orderid
			,@PathVariable("type") Integer type){
		request.setAttribute("orderid",orderid );
		User user=(User) request.getSession().getAttribute("userinfo");
		ProductType ptype = new ProductType();
		ptype.setCompanyid(user.getCompanyid());
		ptype.setFlag(1);
		List<ProductType> list=this.productTypeService.findProductTypeList(ptype);
		request.setAttribute("ProductType_list",list );

		if(type==1 || type==2){
			ProductTable pt=new ProductTable();
			pt.setCompanyid(user.getCompanyid());
			pt.setFlag(1);
			List<ProductTable> ProductTable_list_1=this.commonService.findProductTable(pt);
			pt.setFlag(2);
			List<ProductTable> ProductTable_list_2=this.commonService.findProductTable(pt);
			
			request.setAttribute("ProductTable_list_1",ProductTable_list_1 );
			request.setAttribute("ProductTable_list_2",ProductTable_list_2 );
			
			
		}

		request.setAttribute("type", type);
		String str="orders/addorder_detail_door";
		switch(type){
			case 1:  str="orders/addorder_detail_door";break;
			case 2:  str="orders/addorder_detail_loop";break;
		}
		return str;
	}
}
